package cn.edu.zucc.service.impl;

import cn.edu.zucc.dao.EduExpMapper;
import cn.edu.zucc.entity.EduExp;
//import cn.edu.zucc.repository.EduExpMapper;
import cn.edu.zucc.service.EduExpService;
import cn.edu.zucc.util.ReturnT;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @description edu_exp
 * @author zhengkai.blog.csdn.net
 * @date 2022-04-13
 */
@Service
@Slf4j
public class EduExpServiceImpl implements EduExpService {

	@Resource
	private EduExpMapper eduExpMapper;


	@Override
	public Object insert(EduExp eduExp) {

		// valid
		if (eduExp == null) {
			return ReturnT.error("必要参数缺失");
        }

		eduExpMapper.insert(eduExp);
        return ReturnT.success();
	}


	@Override
	public Object delete(int id) {
		int ret = eduExpMapper.delete(id);
		return ret>0?ReturnT.success():ReturnT.error();
	}


	@Override
	public Object update(EduExp eduExp) {
		int ret = eduExpMapper.update(eduExp);
		return ret>0?ReturnT.success():ReturnT.error();
	}

    @Override
    public Object save(EduExp eduExp) {
        Integer id = eduExp.getId();
        log.info("eduExp {}",eduExp);
        if (id==null) {
            int insert = eduExpMapper.insert(eduExp);
            return ReturnT.success();
        }
        EduExp load = eduExpMapper.load(eduExp.getId());
        if (load==null) {
            int insert = eduExpMapper.insert(eduExp);
//            if(insert)
            return ReturnT.success();
        }
        eduExpMapper.update(eduExp);
        return  ReturnT.success();
    }


    @Override
	public EduExp load(int id) {
		return eduExpMapper.load(id);
	}


	@Override
	public Map<String,Object> pageList(int offset, int pageSize) {

		List<EduExp> pageList = eduExpMapper.pageList(offset, pageSize);
		int totalCount = eduExpMapper.pageListCount(offset, pageSize);

		// result
		Map<String, Object> result = new HashMap<String, Object>();
//		result.put("pageList", pageList);
		result.put("content", pageList);
		result.put("totalCount", totalCount);

		return result;
	}

}
